package project7.Storage;

/**
 * This class represents a Table in the restaraunt.
 * It is associated with a Server and a Check, and can be
 * open or closed
 * @author root
 */
public class Table {

    /*------ Private Variables -----------------------------------------------*/

    private Server server = null;
    private Check check = null;
    private int number = 0;
    private boolean open = false;

    /*------ Constructors ----------------------------------------------------*/

    /**
     * This creates a Table that is closed and not associated with a server
     * @param tableNumber
     */
    public Table(int tableNumber){
        number = tableNumber;
    }
    
    /**
     * This creates a table with number tableNumber,
     * associated with Server serv,
     * and with an order on Check chk.
     * By using this constructor the table will be opened
     * @param tableNumber
     * @param srv
     * @param chk
     */
    public Table(int tableNumber, Server srv, Check chk){
        number = tableNumber;
        server = srv;
        check = chk;
        open = true;
    }
    
    /*------ Accessors and Mutators ------------------------------------------*/
    
    /**
     *
     * @return the Server for the table
     */
    public Server getServer(){ return server; }
    /**
     * This will change the server for the table.
     * If there is a server for the table, the table must be open,
     * so the open flag will be set to true.
     * @param serv new Server for the table
     */
    public void setServer(Server serv){
        server = serv;
        open = true;
    }
    
    /**
     *
     * @return the Check for the table
     */
    public Check getCheck(){ return check; }
    /**
     *
     * @param chk new Check to add to to the table
     */
    public void setCheck(Check chk){ check = chk; }

    /**
     *
     * @return the ID/number of this table
     */
    public int getNumber(){ return number; }
    /**
     * 
     * @param num change the number/ID of the table to num
     */
    public void setNumber(int num){ number = num; }

    /**
     * @return the open flag
     */
    public boolean isOpen() {
        return open;
    }

    /**
     * @param open set open to param
     */
    public void setOpen(boolean open) {
        this.open = open;
    }

    /**
     * This will open the table (set open to true)
     */
    public void open() {
        this.open = true;
    }

    /**
     * This will clost the table (set open to false)
     */
    public void close() {
        this.open = false;
    }

    /*------ Overrides -------------------------------------------------------*/

    /**
     *
     * @return String of Table data
     */
    @Override
    public String toString(){
        String str = "";

        str += "Table Number = " + number + "\n";
        str += "Server - " + server.getLastName() +
                ", " + server.getFirstName() + "\n";
        str += check.toString();

        return str;
    }



}
